<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="apple">
        <span @click="fn1('luoli',$event)">苹果</span>
        <button @click="fn(1)">-</button>
        <span>{{num}}箱</span>
        <button @click="fn(0)">+</button>
        <button @click="fn(2)">一键添加</button>
    </div>
    <script src="../vue2.js"></script>
    <script>
        const vm = new Vue({
            el:'#apple',
            data() {
                return{
                    msg: {
                        name: '洛璃'
                    },
                    bool:true,
                    num: 0
                }
            },
            methods: {
                //各种函数
                down(){
                    this.num--
                    this.num = Math.max(--(this.num),0)
                },
                up(){
                    this.num++
                },
                addNum(){
                    setTimeout(() => {
                        this.num += 300
                    },3000)
                },
                fn(number){
                    if(number==1){
                        this.num--
                        this.num = Math.max(--(this.num),0)
                    }else if(number==0){
                        this.num++
                    }else{
                        setTimeout(() => {
                        this.num += 300
                    },3000)
                    }
                },
                fn1(e,event){
                    console.log(e,event);
                }
            }
        })
    </script>
</body>
</html>